package vip.liux.front.application.clients;

import org.slf4j.Logger;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

@FeignClient(name = "self", url = "http://localhost:5601",
        configuration = SelfFeignClient.SelfFeignClientConfiguration.class,
        fallback = SelfFeignClient.SelfFeignClientFallback.class
)
public interface SelfFeignClient {
    @GetMapping("/api/open-api/bilibili")
    List<OpenApiFeignClient.BilibiliDto> bilibili();

    class SelfFeignClientFallback implements SelfFeignClient {

        private static final Logger logger = getLogger(SelfFeignClientFallback.class);

        @Override
        public List<OpenApiFeignClient.BilibiliDto> bilibili() {
            logger.error("bilibili fallback");
            return List.of();
        }
    }

    class SelfFeignClientConfiguration {
        @Bean
        public SelfFeignClientFallback selfFeignClientFallback() {
            return new SelfFeignClientFallback();
        }
    }
}
